package com.ruoyi.entry.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.entry.domain.MEntry;
import com.ruoyi.entry.service.IMEntryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/entry/entry")
public class MEntryController extends BaseController
{
    @Autowired
    private IMEntryService mEntryService;

    /**
     * 查询入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:list')")
    @GetMapping("/list")
    public TableDataInfo list(MEntry mEntry)
    {
        startPage();
        List<MEntry> list = mEntryService.selectMEntryList(mEntry);
        return getDataTable(list);
    }

    /**
     * 导出入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:export')")
    @Log(title = "入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MEntry mEntry)
    {
        List<MEntry> list = mEntryService.selectMEntryList(mEntry);
        ExcelUtil<MEntry> util = new ExcelUtil<MEntry>(MEntry.class);
        util.exportExcel(response, list, "入库管理数据");
    }

    /**
     * 获取入库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:query')")
    @GetMapping(value = "/{entryId}")
    public AjaxResult getInfo(@PathVariable("entryId") Long entryId)
    {
        return success(mEntryService.selectMEntryByEntryId(entryId));
    }

    /**
     * 新增入库管理
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:add')")
    @Log(title = "入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MEntry mEntry)
    {
        return toAjax(mEntryService.insertMEntry(mEntry));
    }

    /**
     * 修改入库管理
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:edit')")
    @Log(title = "入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MEntry mEntry)
    {
        return toAjax(mEntryService.updateMEntry(mEntry));
    }

    /**
     * 删除入库管理
     */
    @PreAuthorize("@ss.hasPermi('entry:entry:remove')")
    @Log(title = "入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entryIds}")
    public AjaxResult remove(@PathVariable Long[] entryIds)
    {
        return toAjax(mEntryService.deleteMEntryByEntryIds(entryIds));
    }

    /**
     * 获取仓库列表
     */
    @GetMapping("/getWarehouseList")
    public AjaxResult getWarehouseList()
    {
        return success(mEntryService.selectWarehouseList());
    }

    /**
     * 获取商品列表
     */
    @GetMapping("/getcommodityList")
    public AjaxResult getcommodityList()
    {
        return success(mEntryService.selectCommodityList());
    }
}
